]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
status/system: Use Intl to format battery percentage
authorFlorian Müllner <fmuellner@gnome.org>
Thu, 21 Sep 2023 18:55:31 +0000 (20:55 +0200)
committerMarge Bot <marge-bot@gnome.org>
Fri, 22 Sep 2023 17:03:17 +0000 (17:03 +0000)
The exact way of formatting a percentage value is locale specific:
https://en.wikipedia.org/wiki/Percent_sign#Correct_style.

We account for that by marking the string for translations, but then
get it wrong for the default US locale (go us!).

But given that the javascript engine itself provides us with a way
of formatting a percentage in a locale-specific way, that seems the
better option than putting the burden on our own developers and
translators.

Closes: https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/7005
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2966>

js/ui/status/system.js

index 8680b0bddb39b2eac92ac15c5adbef7e4e39360e..ff9fa56241e34de962c9ad7cd5bc7640483066ce 100644 (file)
@@ -93,8 +93,9 @@ const PowerToggle = GObject.registerClass({
             use_default_fallbacks: false,
         });
 
+        const formatter = new Intl.NumberFormat(undefined, {style: 'percent'});
         this.set({
-            title: _('%d\u2009%%').format(this._proxy.Percentage),
+            title: formatter.format(this._proxy.Percentage / 100),
             fallback_icon_name: this._proxy.IconName,
             gicon,
         });